package net.xuele.learn.dancing.tree;

import net.xuele.learn.dancing.TreeNode;

/**
 * 101 对称二叉树
 */
public class IsSymmetric {

    public boolean isSymmetric(TreeNode root) {
        // 返回条件
        if (root == null) {
            return true;
        }
        return isSymmetric(root.left, root.right);
    }

    private boolean isSymmetric(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        }
        if (left == null || right == null || left.val != right.val) {
            return false;
        }
        return isSymmetric(left.left, right.right) && isSymmetric(left.right, right.left);
    }
}
